//
//  ViewController.m
//  ImageStory
//
//  Created by 大帅逼 on 16/1/6.
//  Copyright © 2016年 helloApp. All rights reserved.
//

#import "ViewController.h"
#import "CreateManagerViewController.h"
#import "Header.h"
#import "HeadScrollView.h"
#import "SettingViewController.h"
#import "ReadStoryViewController.h"
#import "SuccessViewController.h"

@interface ViewController ()

@property(nonatomic,strong) UIView                  *bgView;
@property(nonatomic,strong) CAGradientLayer         *gradientLayer;
@property(nonatomic,strong) HeadScrollView          *headScrollView;
@property(nonatomic,strong) UIButton                *settingBtn;
@property(nonatomic,strong) UIImageView             *processImage;
@property(nonatomic,strong) UIImageView             *moreImage;
@property(nonatomic,strong) UIImageView             *logoImage;
@property(nonatomic,strong) UIButton                *moreBtn;
@property(nonatomic,strong) UIButton                *processBtn;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 初始化页面
    [self initView];
    
    // 初始化通知
    [self initNotification];
}

/* - - - - - -- - - - - - - - -页面相关设置 - - - - - - - - - -- -  */

- (void) initView {

    // 设置背景色
    [self.view setBackgroundColor:[UIColor blackColor]];
    
    [self.view addSubview:self.headScrollView];
    
    [self.headScrollView.layer addSublayer:self.gradientLayer];
    
    [self.view addSubview:self.settingBtn];
    
    [self.view addSubview:self.processImage];
    
    [self.view addSubview:self.moreImage];
    
    [self.view addSubview:self.logoImage];
    
    [self.view addSubview:self.processBtn];
    
    [self.view addSubview:self.moreBtn];
}

- (void) initNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action_moreClickEvent) name:@"showReadStoryVC" object:nil];
}

/* - - - - - -- - - - - - - - -点击事件相关设置 - - - - - - - - - -- -  */

- (void) action_showSuccessVC {

    SuccessViewController *successVC = [[SuccessViewController alloc] init];
    
    [successVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    
    [self presentViewController:successVC animated:YES completion:nil];
}

- (void) action_processClickEvent {
    
    CreateManagerViewController *createStroyManger = [CreateManagerViewController shardManger];
    
    [self presentViewController:createStroyManger animated:YES completion:nil];
}

- (void) action_settingClickEvent {

    SettingViewController *settingVC = [[SettingViewController alloc] init];
    
    UINavigationController *settingNav = [[UINavigationController alloc] initWithRootViewController:settingVC];
    
    [self presentViewController:settingNav animated:YES completion:nil];
}

- (void) action_moreClickEvent{

    ReadStoryViewController *readStroyVc = [[ReadStoryViewController alloc] init];
    
    UINavigationController *readNav = [[UINavigationController alloc] initWithRootViewController:readStroyVc];

    [self presentViewController:readNav animated:YES completion:nil];
}

+ (UIViewController *)readCurrHomeViewController {

    return self;
}

#pragma mark -- 懒加载
- (UIView *)bgView {
    
    if (!_bgView) {
        
        _bgView = [[UIView alloc] initWithFrame:self.view.frame];
        
    }
    
    return _bgView;
}

// 设置渐变
- (CAGradientLayer *)gradientLayer {
    
    if (!_gradientLayer) {
        
        _gradientLayer = [CAGradientLayer layer];
        
        [_gradientLayer setFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - My_Height(100))];
        
        UIColor *startColor = [UIColor clearColor];
        
        UIColor *endColor = [UIColor blackColor];
        
        _gradientLayer.colors = @[(__bridge id)startColor.CGColor,(__bridge id)endColor.CGColor];
        
        _gradientLayer.startPoint = CGPointMake(0.5, 0.0);// 设置颜色的起点
        
        _gradientLayer.endPoint = CGPointMake(0.5, 1.0);
        
        _gradientLayer.locations = @[@0.2,@0.8];
        
    }
    return _gradientLayer;
}

- (HeadScrollView *)headScrollView {
    
    if (!_headScrollView) {
        
        _headScrollView = [[HeadScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - My_Height(200)) images:[NSArray arrayWithObjects:@"image03",@"image04",@"image02",@"image03",@"image04", nil]];
    }
    return _headScrollView;
}

- (UIButton *)settingBtn {

    if (!_settingBtn) {
        
        _settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_settingBtn setFrame:CGRectMake(SCREEN_W - My_Width(60), My_Height(30), My_Height(30), My_Height(30))];
        
        [_settingBtn addTarget:self action:@selector(action_settingClickEvent) forControlEvents:UIControlEventTouchUpInside];
        
        [_settingBtn setImage:[UIImage imageNamed:@"home_set"] forState:UIControlStateNormal];
    }
    
    return _settingBtn;
}

- (UIImageView *)processImage {
    
    if (!_processImage) {
        
        _processImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_W / 2 + My_Width(50), SCREEN_H - My_Height(170), My_Height(40), My_Height(40))];
        
        [_processImage setUserInteractionEnabled:YES];
        
        UITapGestureRecognizer *moreTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_moreClickEvent)];
        
        [_processImage addGestureRecognizer:moreTap];
        
        
        [_processImage setImage:[UIImage imageNamed:@"process"]];
    }
    
    return _processImage;
}

- (UIImageView *)moreImage {
    
    if (!_moreImage) {
        
        _moreImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_W / 2 - My_Width(90), SCREEN_H - My_Height(170), My_Height(40), My_Height(40))];
        
        [_moreImage setUserInteractionEnabled:YES];
        
        UITapGestureRecognizer *processTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_processClickEvent)];
        
        [_moreImage addGestureRecognizer:processTap];
        
        [_moreImage setImage:[UIImage imageNamed:@"more"]];
        
    }
    
    return _moreImage;
}

- (UIImageView *)logoImage {
    
    if (!_logoImage) {
        
        _logoImage = [[UIImageView alloc] init];
        
        [_logoImage setBounds:CGRectMake(0, 0, My_Height(250), My_Height(250))];
        
        [_logoImage setCenter:CGPointMake(SCREEN_W / 2, SCREEN_H - My_Height(270))];
        
        [_logoImage setImage:[UIImage imageNamed:@"logo"]];
    }
    
    return _logoImage;
}

- (UIButton *)moreBtn {
    
    if (!_moreBtn) {
        
        _moreBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        
        [_moreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [_moreBtn setFrame:CGRectMake(SCREEN_W / 2 + My_Width(30), SCREEN_H - My_Height(120), My_Height(80), My_Height(40))];
        
        [_moreBtn setTitle:@"阅读故事" forState:UIControlStateNormal];
        
        [_moreBtn.titleLabel setFont:[UIFont systemFontOfSize:My_Height(17)]];
        
        [_moreBtn addTarget:self action:@selector(action_moreClickEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _moreBtn;
}

- (UIButton *)processBtn {
    
    if (!_processBtn) {
        
        _processBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        
        [_processBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [_processBtn setFrame:CGRectMake(SCREEN_W / 2 - My_Width(110), SCREEN_H - My_Height(120), My_Height(80), My_Height(40))];
        
        [_processBtn setTitle:@"书写照片" forState:UIControlStateNormal];
        
        [_processBtn.titleLabel setFont:[UIFont systemFontOfSize:My_Height(17)]];
        
        [_processBtn addTarget:self action:@selector(action_processClickEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _processBtn;
}

@end
